<?php

// +----------------------------------------------------------------------
// | 版权所有 2017-2027 云南环拓科技有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.yn123.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// | 注意：  这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用,
// |        不允许对程序代码以任何形式任何目的的再发布。
// +----------------------------------------------------------------------
// | Author: feraner <feraner@163.com> 
// | Date: 2019/11/19
// +----------------------------------------------------------------------

namespace app\agency\controller;

use app\common\facade\Arr;
use library\Controller;
use think\Db;

/**
 *
 * Class AgentBase
 * @package app\agency\controller
 * @author feraner<feraner@163.com>
 * @date 2019/11/19
 */
class AgentBase extends Controller
{

    /**
     * 当前登录的用户ID
     * @var null
     */
    protected $userId = null;

    /**
     * 当前登录的用户信息
     * @var null
     */
    protected $user = null;


    /**
     * 代理商总账号ID
     * @var null
     */
    protected $agentId = null;

    /**
     * 代理商总账号信息
     * @var mixed|null
     */
    protected $agentUser = null;


    /**
     * AgentBase constructor.
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function __construct()
    {
        parent::__construct();

        //提取登录用户信息
        $loginUser = session('agent_user');
        if (Arr::get($loginUser, 'pid')) {
            $this->agentId = Arr::get($loginUser, 'pid');
            $this->agentUser = Db::name('system_agent_user')
                ->where('id', $this->agentId)
                ->find() ?: [];
        } else {
            $this->agentId = Arr::get($loginUser, 'id');
            $this->agentUser = $loginUser;
        }
        if (Arr::get($loginUser, 'id')) {
            $this->userId = Arr::get($loginUser, 'id');
            $this->user = $loginUser;
        }


        $this->__publicAssign();

    }



    private function __publicAssign()
    {

        $this->assign('agentId', $this->agentId);
    }








}
